package com.umerclass.ui.anmo;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.style.cityjd.JDCityConfig;
import com.lljjcoder.style.cityjd.JDCityPicker;
import com.umerclass.R;
import com.umerclass.frame.model.InfoResult;
import com.umerclass.frame.model.MsgBean;
import com.umerclass.frame.okhttp.OkSimpleRequest;
import com.umerclass.frame.ui.activity.BaseActivity;
import com.umerclass.utils.Constants;
import com.umerclass.utils.EventConstants;
import com.umerclass.utils.screen.ScreenUtil;

import java.util.regex.Pattern;
import butterknife.BindView;
import butterknife.OnClick;

public class JoinActivity extends BaseActivity {

    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;
    @BindView(R.id.tv3)
    TextView tv3;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.tv_code_get)
    TextView tvCodeGet;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.et_area)
    TextView etArea;
    @BindView(R.id.et_people)
    EditText etPeople;
    @BindView(R.id.et_password_login)
    EditText etPasswordLogin;
    @BindView(R.id.et_password_login_sure)
    EditText etPasswordLoginSure;
    @BindView(R.id.et_password_pay)
    EditText etPasswordPay;
    @BindView(R.id.et_password_pay_sure)
    EditText etPasswordPaySure;
    @BindView(R.id.linear1)
    LinearLayout linear1;
    @BindView(R.id.et_name_2)
    EditText etName2;
    @BindView(R.id.et_phone_2)
    EditText etPhone2;
    @BindView(R.id.tv_code_get_2)
    TextView tvCodeGet2;
    @BindView(R.id.et_code_2)
    EditText etCode2;
    @BindView(R.id.et_area_2)
    TextView etArea2;
    @BindView(R.id.et_people_2)
    EditText etPeople2;
    @BindView(R.id.et_password_login_2)
    EditText etPasswordLogin2;
    @BindView(R.id.et_password_login_sure_2)
    EditText etPasswordLoginSure2;
    @BindView(R.id.et_password_pay_2)
    EditText etPasswordPay2;
    @BindView(R.id.et_password_pay_sure_2)
    EditText etPasswordPaySure2;
    @BindView(R.id.linear2)
    LinearLayout linear2;
    @BindView(R.id.et_shopname_3)
    EditText etShopname3;
    @BindView(R.id.et_name_3)
    EditText etName3;
    @BindView(R.id.et_phone_3)
    EditText etPhone3;
    @BindView(R.id.tv_code_get_3)
    TextView tvCodeGet3;
    @BindView(R.id.et_code_3)
    EditText etCode3;
    @BindView(R.id.et_area_3)
    TextView etArea3;
    @BindView(R.id.et_jiqi_number_3)
    EditText etJiqiNumber3;
    @BindView(R.id.et_people_3)
    EditText etPeople3;
    @BindView(R.id.et_password_login_3)
    EditText etPasswordLogin3;
    @BindView(R.id.et_password_login_sure_3)
    EditText etPasswordLoginSure3;
    @BindView(R.id.et_password_pay_3)
    EditText etPasswordPay3;
    @BindView(R.id.et_password_pay_sure_3)
    EditText etPasswordPaySure3;
    @BindView(R.id.linear3)
    LinearLayout linear3;
    @BindView(R.id.iv_check)
    ImageView ivCheck;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    @BindView(R.id.tv_xieyi)
    TextView tvXieyi;
    private JDCityPicker cityPicker;
    private JDCityConfig.ShowType mWheelType = JDCityConfig.ShowType.PRO_CITY_DIS;
    private JDCityConfig jdCityConfig = new JDCityConfig.Builder().build();
    private boolean select = false;
    private int type = 1;//一级代理 二级代理  店家
    private boolean getCode1 = false;
    CountDownTimer timer1 = new CountDownTimer(60000, 1000) {

        @Override
        public void onTick(long millisUntilFinished) {
            tvCodeGet.setText(millisUntilFinished / 1000 + "秒");
            getCode1 = false;
        }

        @Override
        public void onFinish() {
            tvCodeGet.setText("重新获取验证码");
            getCode1 = true;
        }
    };

    private boolean clcikOne = false;
    private boolean clcikTwo = false;
    private boolean clcikThree = false;

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer1.cancel();
    }

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public boolean isSupportSwipeBack() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_join;
    }

    @Override
    public void init() {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.white));
        setArea();
        initOne();
        initTwo();
        initThree();
    }

    @Override
    public void loadData() {

    }

    @OnClick({R.id.tv1, R.id.tv2, R.id.tv3, R.id.iv_check, R.id.tv_submit,
            R.id.et_area, R.id.et_area_2, R.id.et_area_3, R.id.linear_back, R.id.tv_code_get, R.id.tv_xieyi})
    public void OnClick(View view) {
        switch (view.getId()) {
            //注册协议
            case R.id.tv_xieyi:
                if(dialogOne == null){
                    createDialogOne();
                }else{
                    if(!dialogOne.isShowing()){
                        dialogOne.show();
                    }
                }
                break;
            case R.id.linear_back:
                finish();
                break;
            case R.id.tv1:
                if (type == 1) {
                    return;
                } else {
                    select = false;
                    tv1.setBackgroundResource(R.drawable.shape_one_press);
                    tv2.setBackgroundResource(R.drawable.shape_one_normal);
                    tv3.setBackgroundResource(R.drawable.shape_one_normal);
                    tv1.setTextColor(Color.parseColor("#ffffff"));
                    tv2.setTextColor(Color.parseColor("#212121"));
                    tv3.setTextColor(Color.parseColor("#212121"));
                    linear1.setVisibility(View.VISIBLE);
                    linear2.setVisibility(View.GONE);
                    linear3.setVisibility(View.GONE);
                    type = 1;
                    setEmptyOne();
                    setClickOne();
                }
                break;
            case R.id.tv2:
                if (type == 2) {
                    return;
                } else {
                    select = false;
                    tv1.setBackgroundResource(R.drawable.shape_one_normal);
                    tv2.setBackgroundResource(R.drawable.shape_one_press);
                    tv3.setBackgroundResource(R.drawable.shape_one_normal);
                    tv1.setTextColor(Color.parseColor("#212121"));
                    tv2.setTextColor(Color.parseColor("#ffffff"));
                    tv3.setTextColor(Color.parseColor("#212121"));
                    linear1.setVisibility(View.GONE);
                    linear2.setVisibility(View.VISIBLE);
                    linear3.setVisibility(View.GONE);
                    type = 2;
                    setEmptyTwo();
                    setClickTwo();
                }
                break;
            case R.id.tv3:
                if (type == 3) {
                    return;
                } else {
                    select = false;
                    tv1.setBackgroundResource(R.drawable.shape_one_normal);
                    tv2.setBackgroundResource(R.drawable.shape_one_normal);
                    tv3.setBackgroundResource(R.drawable.shape_one_press);
                    tv1.setTextColor(Color.parseColor("#212121"));
                    tv2.setTextColor(Color.parseColor("#212121"));
                    tv3.setTextColor(Color.parseColor("#ffffff"));
                    linear1.setVisibility(View.GONE);
                    linear2.setVisibility(View.GONE);
                    linear3.setVisibility(View.VISIBLE);
                    type = 3;
                    setEmptyThree();
                    setClickThree();
                }
                break;
            case R.id.iv_check:
                if (select) {
                    select = false;
                    tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
                    ivCheck.setBackgroundResource(R.drawable.check_normal);
                } else {
                    select = true;
                    ivCheck.setBackgroundResource(R.drawable.check_press);
                    if (type == 1) {
                        setClickOne();
                    } else if (type == 2) {
                        setClickTwo();
                    } else if (type == 3) {
                        setClickThree();
                    }
                }
                break;
            case R.id.tv_submit:
                if (type == 1) {
                    if (clcikOne) {
                        if (!select) {
                            showToast("请同意相关协议");
                        } else {
                            if (!loginPassword1_one.equals(loginPassword1_two)) {
                                showToast("登录密码与确认密码不同");
                                return;
                            } else {
                                if (!payPassword1_one.equals(payPassword1_two)) {
                                    showToast("支付密码与确认密码不同");
                                    return;
                                }
                                showProgress("正在请求...");
                                OkSimpleRequest request = new OkSimpleRequest<>(R.id.registerUser,
                                        Constants.registerUser);
                                request.addParams("name", name1);
                                request.addParams("phone", phone1);
                                request.addParams("loginPassword", loginPassword1_one);
                                request.addParams("payPassword", payPassword1_one);
                                request.addParams("provinceName", proName);
                                request.addParams("cityName", cityName);
                                request.addParams("areaName", disName);
                                request.addParams("inviteBusinessPhone", inviteBusinessPhone1);
                                request.addParams("businessType", 1);
                                request.addParams("authCode", code1);
                                request.addHeadParams("userType", 1);
                                requestOkhttpSimple(request);
                            }
                        }
                    }
                }
                break;
            case R.id.et_area:
                showJD();
                break;
            case R.id.et_area_2:
                showJD();
                break;
            case R.id.et_area_3:
                showJD();
                break;
            //一级代理获取验证码
            case R.id.tv_code_get:

                if (!TextUtils.isEmpty(phone1)) {
                    if (isPhoneNumber(phone1)) {
                        timer1.start();
                        OkSimpleRequest request = new OkSimpleRequest<>(R.id.authPhone,
                                Constants.authPhone);
                        request.addParams("phone", phone1);
                        requestOkhttpSimple(request);
                    } else {
                        showToast("请输入正确的手机号码");
                    }
                }
                break;
            default:
                break;
        }
    }

    private boolean isPhoneNumber(String input) {// 判断手机号码是否规则
        String regex = "(1[0-9][0-9]|15[0-9]|18[0-9])\\d{8}";
        Pattern p = Pattern.compile(regex);
        return p.matches(regex, input);//如果不是号码，则返回false，是号码则返回true

    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

        switch (what) {
            case R.id.authPhone:
                showToast(t.getDesc());
                break;
            case R.id.registerUser:
                hideProgress();
                showToast(t.getDesc());
                break;
            default:
                break;
        }
    }

    @Override
    protected void onFail(int what, InfoResult t) {
        switch (what) {
            case R.id.authPhone:
                showToast(t.getDesc());
                break;
            case R.id.registerUser:
                hideProgress();
                showToast(t.getDesc());
                MsgBean msgBean = new MsgBean();
                msgBean.setFlag(EventConstants.registerSuccess);
                if (type == 1) {
                    msgBean.setObject(phone1);
                } else if (type == 2) {
                    msgBean.setObject(phone2);
                } else if (type == 3) {
                    msgBean.setObject(phone3);
                }
                getEventBus().post(msgBean);
                break;
            default:
                break;
        }
    }

    private void setArea() {
        jdCityConfig.setShowType(mWheelType);
        cityPicker = new JDCityPicker();
        //初始化数据
        cityPicker.init(this);
        //设置JD选择器样式位只显示省份和城市两级
        cityPicker.setConfig(jdCityConfig);
        cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                if (province != null) {
                    if (type == 1) {
                        proName = province.getName();
                        proId = province.getId();
                    } else if (type == 2) {
                        proName2 = province.getName();
                        proId2 = province.getId();
                    } else if (type == 3) {
                        proName3 = province.getName();
                        proId3 = province.getId();
                    }
                }
                if (city != null) {
                    if (type == 1) {
                        cityName = city.getName();
                        cityId = city.getId();
                    } else if (type == 2) {
                        cityName2 = city.getName();
                        cityId2 = city.getId();
                    } else if (type == 3) {
                        cityName3 = city.getName();
                        cityId3 = city.getId();
                    }
                }
                if (district != null) {
                    if (type == 1) {
                        disName = district.getName();
                        disId = district.getId();
                    } else if (type == 2) {
                        disName2 = district.getName();
                        disId2 = district.getId();
                    } else if (type == 3) {
                        disName3 = district.getName();
                        disId3 = district.getId();
                    }
                }
                if (type == 1) {
                    etArea.setText(proName + cityName + disName);
                } else if (type == 2) {
                    etArea2.setText(proName2 + cityName2 + disName2);
                } else if (type == 3) {
                    etArea3.setText(proName3 + cityName3 + disName3);
                }
            }

            @Override
            public void onCancel() {
            }
        });
    }

    private void showJD() {
        cityPicker.showCityPicker();
    }

    /**
     * 一级代理
     */
    private String name1 = "";
    private String phone1 = "";

    private String code1 = "";
    private String proName = "";
    private String cityName = "";

    private String disName = "";
    private String proId = "";
    private String cityId = "";
    private String disId = "";
    private String inviteBusinessPhone1 = "";
    private String loginPassword1_one = "";

    private String loginPassword1_two = "";
    private String payPassword1_one = "";
    private String payPassword1_two = "";

    private void initOne() {

        etPasswordPaySure.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword1_two = "";
                } else {
                    payPassword1_two = s.toString();
                }
                setClickOne();
            }
        });

        etPasswordPay.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword1_one = "";
                } else {
                    payPassword1_one = s.toString();
                }
                setClickOne();
            }
        });

        etPasswordLoginSure.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword1_two = "";
                } else {
                    loginPassword1_two = s.toString();
                }
                setClickOne();
            }
        });

        etPasswordLogin.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword1_one = "";
                } else {
                    loginPassword1_one = s.toString();
                }
                setClickOne();
            }
        });

        etPeople.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    inviteBusinessPhone1 = "";
                } else {
                    inviteBusinessPhone1 = s.toString();
                }
                setClickOne();
            }
        });

        etCode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    code1 = "";
                } else {
                    code1 = s.toString();
                }
                setClickOne();
            }
        });

        etName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    name1 = "";
                } else {
                    name1 = s.toString();
                }
                setClickOne();
            }
        });

        etPhone.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    phone1 = "";
                } else {
                    phone1 = s.toString();
                }
                setClickOne();
            }
        });
    }

    private void initTwo() {

        etPasswordPaySure2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword2_two = "";
                } else {
                    payPassword2_two = s.toString();
                }
                setClickTwo();
            }
        });

        etPasswordPay2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword2_one = "";
                } else {
                    payPassword2_one = s.toString();
                }
                setClickTwo();
            }
        });

        etPasswordLoginSure2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword2_two = "";
                } else {
                    loginPassword2_two = s.toString();
                }
                setClickTwo();
            }
        });

        etPasswordLogin2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword2_one = "";
                } else {
                    loginPassword2_one = s.toString();
                }
                setClickTwo();
            }
        });

        etPeople2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    inviteBusinessPhone2 = "";
                } else {
                    inviteBusinessPhone2 = s.toString();
                }
                setClickTwo();
            }
        });

        etCode2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    code2 = "";
                } else {
                    code2 = s.toString();
                }
                setClickTwo();
            }
        });

        etName2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    name2 = "";
                } else {
                    name2 = s.toString();
                }
                setClickTwo();
            }
        });

        etPhone2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    phone2 = "";
                } else {
                    phone2 = s.toString();
                }
                setClickTwo();
            }
        });
    }

    private void initThree() {

        etPasswordPaySure3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword3_two = "";
                } else {
                    payPassword3_two = s.toString();
                }
                setClickThree();
            }
        });

        etPasswordPay3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    payPassword3_one = "";
                } else {
                    payPassword3_one = s.toString();
                }
                setClickThree();
            }
        });

        etPasswordLoginSure3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword3_two = "";
                } else {
                    loginPassword3_two = s.toString();
                }
                setClickThree();
            }
        });

        etPasswordLogin3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    loginPassword3_one = "";
                } else {
                    loginPassword3_one = s.toString();
                }
                setClickThree();
            }
        });

        etPeople3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    inviteBusinessPhone3 = "";
                } else {
                    inviteBusinessPhone3 = s.toString();
                }
                setClickThree();
            }
        });

        etCode3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    code3 = "";
                } else {
                    code3 = s.toString();
                }
                setClickThree();
            }
        });

        etName3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    name3 = "";
                } else {
                    name3 = s.toString();
                }
                setClickThree();
            }
        });

        etPhone3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    phone3 = "";
                } else {
                    phone3 = s.toString();
                }
                setClickThree();
            }
        });

        etShopname3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    shopName3 = "";
                } else {
                    shopName3 = s.toString();
                }
                setClickThree();
            }
        });

        etJiqiNumber3.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (TextUtils.isEmpty(s.toString())) {
                    number3 = "";
                } else {
                    number3 = s.toString();
                }
                setClickThree();
            }
        });
    }

    private void setClickOne() {
        if (TextUtils.isEmpty(name1) || TextUtils.isEmpty(phone1)
                || TextUtils.isEmpty(code1) || TextUtils.isEmpty(proName) || TextUtils.isEmpty(cityName)
                || TextUtils.isEmpty(disName) || TextUtils.isEmpty(inviteBusinessPhone1) || TextUtils.isEmpty(loginPassword1_one)
                || TextUtils.isEmpty(loginPassword1_two) || TextUtils.isEmpty(payPassword1_one) || TextUtils.isEmpty(payPassword1_two)) {
            tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
            clcikOne = false;
        } else {
            if (select) {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_press);
                clcikOne = true;
            } else {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
                clcikOne = false;
            }

        }
    }

    private void setEmptyOne() {

        //倒计时取消
        name1 = "";
        phone1 = "";
        code1 = "";
        proName = "";
        cityName = "";
        disName = "";
        proId = "";
        cityId = "";
        disId = "";
        inviteBusinessPhone1 = "";
        loginPassword1_one = "";
        loginPassword1_two = "";
        payPassword1_one = "";
        payPassword1_two = "";
        etName.setText("");
        etPhone.setText("");
        etCode.setText("");
        etArea.setText("");
        etPeople.setText("");
        etPasswordLogin.setText("");
        etPasswordLoginSure.setText("");
        etPasswordPay.setText("");
        etPasswordPaySure.setText("");
    }

    /**
     * 二级代理
     */
    private String name2 = "";
    private String phone2 = "";
    private String code2 = "";

    private String proName2 = "";
    private String cityName2 = "";
    private String disName2 = "";
    private String proId2 = "";
    private String cityId2 = "";
    private String disId2 = "";

    private String inviteBusinessPhone2 = "";
    private String loginPassword2_one = "";
    private String loginPassword2_two = "";

    private String payPassword2_one = "";
    private String payPassword2_two = "";

    private void setClickTwo() {
        if (TextUtils.isEmpty(name2) || TextUtils.isEmpty(phone2) || TextUtils.isEmpty(code2)
                || TextUtils.isEmpty(proName2) || TextUtils.isEmpty(cityName2) || TextUtils.isEmpty(disName2)
                || TextUtils.isEmpty(inviteBusinessPhone2) || TextUtils.isEmpty(loginPassword2_one) || TextUtils.isEmpty(loginPassword2_two)
                || TextUtils.isEmpty(payPassword2_one) || TextUtils.isEmpty(payPassword2_two)) {
            tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
            clcikTwo = false;
        } else {
            if (select) {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_press);
                clcikTwo = true;
            } else {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
                clcikTwo = false;
            }

        }
    }

    private void setEmptyTwo() {
        //倒计时取消

        name2 = "";
        phone2 = "";
        code2 = "";
        proName2 = "";
        cityName2 = "";
        disName2 = "";
        proId2 = "";
        cityId2 = "";
        disId2 = "";
        inviteBusinessPhone2 = "";
        loginPassword2_one = "";
        loginPassword2_two = "";
        payPassword2_one = "";
        payPassword2_two = "";

        etName2.setText("");
        etPhone2.setText("");
        etCode2.setText("");
        etArea2.setText("");
        etPeople2.setText("");
        etPasswordLogin2.setText("");
        etPasswordLoginSure2.setText("");
        etPasswordPay2.setText("");
        etPasswordPaySure2.setText("");
    }

    /**
     * 店家
     */
    private String shopName3 = "";
    private String name3 = "";
    private String phone3 = "";

    private String code3 = "";
    private String proName3 = "";
    private String cityName3 = "";

    private String disName3 = "";
    private String proId3 = "";
    private String cityId3 = "";
    private String disId3 = "";
    private String number3 = "";
    private String inviteBusinessPhone3 = "";

    private String loginPassword3_one = "";
    private String loginPassword3_two = "";
    private String payPassword3_one = "";

    private String payPassword3_two = "";

    private void setClickThree() {
        if (TextUtils.isEmpty(name3) || TextUtils.isEmpty(phone3) || TextUtils.isEmpty(shopName3)
                || TextUtils.isEmpty(code3) || TextUtils.isEmpty(proName3) || TextUtils.isEmpty(cityName3)
                || TextUtils.isEmpty(disName3) || TextUtils.isEmpty(number3) || TextUtils.isEmpty(inviteBusinessPhone3)
                || TextUtils.isEmpty(loginPassword3_one) || TextUtils.isEmpty(loginPassword3_two) || TextUtils.isEmpty(payPassword3_one)
                || TextUtils.isEmpty(payPassword3_two)) {
            tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
            clcikThree = false;
        } else {
            if (select) {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_press);
                clcikThree = true;
            } else {
                tvSubmit.setBackgroundResource(R.drawable.shape_back_normal);
                clcikThree = false;
            }
        }
    }

    private void setEmptyThree() {
        //倒计时取消
        shopName3 = "";
        name3 = "";
        phone3 = "";
        code3 = "";
        proName3 = "";
        cityName3 = "";
        disName3 = "";
        proId3 = "";
        cityId3 = "";
        disId3 = "";
        number3 = "";
        inviteBusinessPhone3 = "";
        loginPassword3_one = "";
        loginPassword3_two = "";
        payPassword3_one = "";
        payPassword3_two = "";
        etShopname3.setText("");
        etName3.setText("");
        etPhone3.setText("");
        etCode3.setText("");
        etArea3.setText("");
        etJiqiNumber3.setText("");
        etPeople3.setText("");
        etPasswordLogin3.setText("");
        etPasswordLoginSure3.setText("");
        etPasswordPay3.setText("");
        etPasswordPaySure3.setText("");
    }

    private Dialog dialogOne;
    private ImageView imageView;
    private Dialog createDialogOne() {
        if (dialogOne == null) {
            dialogOne = new Dialog(this, R.style.ActionSheetDialogStyle);
            //填充对话框的布局
            View inflate = LayoutInflater.from(this).inflate(R.layout.dialog1, null);
            imageView = (ImageView) inflate.findViewById(R.id.image);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(dialogOne.isShowing()){
                        dialogOne.dismiss();
                    }
                }
            });
            //将布局设置给Dialog
            dialogOne.setContentView(inflate);
            Window dialogWindow = dialogOne.getWindow();
            WindowManager.LayoutParams windowparams = dialogWindow.getAttributes();
            //设置Dialog从窗体底部弹出
            dialogWindow.setGravity(Gravity.CENTER);
            Rect rect = new Rect();
            View view1 = dialogWindow.getDecorView();
            view1.getWindowVisibleDisplayFrame(rect);
            windowparams.width = ScreenUtil.getInstance().getScreenWidth();
            dialogWindow.setAttributes(
                    (WindowManager.LayoutParams) windowparams);
            //获得窗体的属性
//            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//            lp.y = 10;//设置Dialog距离底部的距离
//            //将属性设置给窗体
//            dialogWindow.setAttributes(lp);
            dialogOne.show();
        }
        return dialogOne;
    }
}
